home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0097_Graphical Fades and Palet.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-05  |  2KB  |  83 lines

  1. {
  2. here are some routines, with which you can fade the screen in/out.
  3. How to use:
  4.  
  5.   Fade out: Get the original palette with the GetPal(0,255,pal) command.
  6.             (Of course you have to allocate 768 Bytes Memory for the pal
  7.              pointer first).
  8.             Then call FadePal(Pal,true,steps) and the screen will be
  9.             faded out.
  10.  
  11.   Fade in: Just pass the target-pal. to the Fade-Routine:
  12.  
  13.              FadePal(Targetpal,false,steps).
  14.  
  15. Note: Low step-rates mean high fading speed. }
  16.  
  17.  
  18. Procedure SetPal(Start: byte; Anz: word; pal: pointer); assembler;
  19. asm
  20.   push ds
  21.   cld
  22.   lds si,pal
  23.   mov dx,3c8h
  24.   mov al,start
  25.   out dx,al
  26.   inc dx
  27.   mov ax,anz
  28.   mov cx,ax
  29.   add cx,ax
  30.   add cx,ax
  31.   rep outsb
  32.   pop ds
  33. end;
  34.  
  35.  
  36. Procedure GetPal(Start: byte; Anz: word; pal: pointer); assembler;
  37. asm
  38.   les di,pal
  39.   mov al,start
  40.   mov dx,3c7h
  41.   out dx,al
  42.   inc dx
  43.   mov ax,anz
  44.   mov cx,ax
  45.   add cx,ax
  46.   add cx,ax
  47.  
  48.   mov dx,3c9h
  49.   cld
  50.   rep insb
  51. end;
  52.  
  53.  
  54. Procedure FadePal(OrigPal : pPal; FadeOut : Boolean; steps: byte);
  55. Var
  56.   r,g,b   : byte;
  57.   Fade    : word;
  58.   Pct     : real;
  59.   I       : byte;
  60. begin
  61.   For Fade := 0 to Steps do begin
  62.     Pct := Fade / Steps;
  63.     If FadeOut then Pct := 1 - Pct;
  64.     For I := 0 to 255 do begin
  65.       r := Round(OrigPalI].R * Pct);
  66.       g := Round(OrigPalI].G * Pct);
  67.       b := Round(OrigPalI].B * Pct);
  68.       asm
  69.         mov dx,3c8h
  70.         mov al,i
  71.         out dx,al
  72.         mov dx,3c9h
  73.         mov al,r
  74.         out dx,al
  75.         mov al,g
  76.         out dx,al
  77.         mov al,b
  78.         out dx,al
  79.       end;
  80.     end;
  81.   end;
  82. end;
  83.